//
//  SongCategoryView.m
//  LZMusicPlayer
//
//  Created by wulanzhou on 2016/11/3.
//  Copyright © 2016年 wulanzhou. All rights reserved.
//

#import "SongCategoryView.h"

@interface SongCategoryView (){
    void (^SongCategoryViewButtonBlock) (SongCategoryFunction functionType);
}
@property (nonatomic,strong) UIButton *artButton;
@property (nonatomic,strong) UIButton *categoryButton;
@property (nonatomic,strong) UIButton *albumButton;
@end

@implementation SongCategoryView

+ (instancetype)instancetypeSongCategoryViewOffsetY:(CGFloat)offsetY{

    SongCategoryView *songView=[[SongCategoryView alloc] initWithFrame:CGRectMake(0, offsetY, [UIScreen mainScreen].bounds.size.width, 50)];
    
    return songView;
}

- (instancetype)initWithFrame:(CGRect)frame{

    if (self=[super initWithFrame:frame]) {
        [self addSubview:self.artButton];
        [self addSubview:self.categoryButton];
        [self addSubview:self.albumButton];
    }
    
    return self;
}

- (void)setSongCategoryFinishedClick:(void (^) (SongCategoryFunction functionType))finished{
    SongCategoryViewButtonBlock=finished;
}


- (UIButton *)artButton{

    if (!_artButton) {
        _artButton=[UIButton buttonWithType:UIButtonTypeCustom];
        _artButton.frame=CGRectMake((self.width/2-100)/2, 0, 100, 50);
        [_artButton setTitle:@"歌手" forState:UIControlStateNormal];
        [_artButton addTarget:self action:@selector(btnCategoryClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _artButton;
}

- (UIButton *)categoryButton{
    
    if (!_categoryButton) {
        _categoryButton=[UIButton buttonWithType:UIButtonTypeCustom];
        _categoryButton.frame=CGRectMake((self.width-100)/2, 0, 100, 50);
        [_categoryButton setTitle:@"分类" forState:UIControlStateNormal];
        [_categoryButton addTarget:self action:@selector(btnCategoryClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _categoryButton;
}

- (UIButton *)albumButton{
    
    if (!_albumButton) {
        _albumButton=[UIButton buttonWithType:UIButtonTypeCustom];
        _albumButton.frame=CGRectMake(self.width/2+(self.width/2-100)/2, 0, 100, 50);
        [_albumButton setTitle:@"专辑" forState:UIControlStateNormal];
        [_albumButton addTarget:self action:@selector(btnCategoryClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _albumButton;
}

- (void)btnCategoryClick:(UIButton *)sender{

    SongCategoryFunction type=SongCategoryFunctionNone;
    if (self.artButton==sender) {
        type=SongCategoryFunctionArt;
    }else if (self.categoryButton==sender){
        type=SongCategoryFunctionType;
    }else if (self.albumButton==sender){
        type=SongCategoryFunctionAlbum;
    }
    
    if (SongCategoryViewButtonBlock) {
        SongCategoryViewButtonBlock(type);
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
